package com.chief.hadoop.mr.outputFormat.iterative;

import com.chief.hadoop.mr.outputFormat.FlowBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    FlowBean flowBean = new FlowBean();
    Text text = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split("-----");
        System.out.println("=========");
        System.out.println(line);
        flowBean.setTotal(Long.valueOf(split[1]));
        flowBean.setCnt(Integer.valueOf(split[2]));

        text.set(split[0]);

        context.write(flowBean, text);
    }
}
